<?php

namespace App\Models;

class SysConfig extends BaseModel
{
    protected $table = "sys_config";

    public function __construct()
    {
        parent::__construct();
    }

    public function getList()
    {
        return $this->getPaginate();
    }

    public function getOne($where, $fields = '*')
    {
        return $this->_getOne($where, $fields);
    }

    public function add($request)
    {
        $is_config = $this->getOne(['field' => $request['field']], 'id');
        if($is_config){
            return -1;
        }
        isset($request['group_id']) && $this->group_id = $request['group_id'];
        isset($request['title']) && $this->title = $request['title'];
        isset($request['field']) && $this->field = $request['field'];
        isset($request['type']) && $this->type = $request['type'];
        isset($request['value']) && $this->value = $request['value'];
        isset($request['remark']) && $this->remark = $request['remark'];
        $this->save();
        return $this->id ? $this->id : 0;
    }

    public function up($where, $data)
    {
        return $this->_updata($where, $data);
    }

}
